package com.jydd.mybroadcastreceiverstudy;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

/**
 * created by 韦敏敏
 * on 2019/12/27
 */
public class MainFragment extends Fragment {
    @Nullable
    @Override
    public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.layout_fragment_main, container, false);
        view.findViewById(R.id.btnSendStaticBroadcast).setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Util.STATIC_RECEIVER_ACTION);
                intent.setPackage(getContext().getPackageName());
                getActivity().sendBroadcast(intent);
            }
        });
        view.findViewById(R.id.btnSendDynamicBroadcast).setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Util.DYNAMIC_RECEIVER_ACTION);
                LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
            }
        });
        return view;
    }
}
